package com.explorati.interview.interview.chapterfour;

public class ReverseStringTest {

	public static void main(String[] args) {
		String str = "I love you and me.";
		System.out.println("原始字符串：" + str);

		System.out.print("反转后字符串 : ");
		for (int i = str.length() - 1; i >= 0; i--) {
			System.out.print(str.charAt(i));
		}
		System.out.println();
		System.out.println("====================");

		// 也可以转换成数组后再反转，不过有点多此一举
		char[] data = str.toCharArray();
		System.out.print("反转后的字符串");
		for (int i = data.length; i > 0; i--) {
			System.out.print(data[i - 1]);
		}
		System.out.println();
		System.out.println("======================");

		System.out.print("反转后的字符串为：");
		StringBuffer str2 = new StringBuffer();
		for (int i = str.length() - 1; i >= 0; i--) {
			str2.append(str.charAt(i));
		}
		System.out.println(str2);

		System.out.println();
		StringBuffer buff = new StringBuffer(str);
		System.out.print("反转后的字符串为：");
		System.out.print(buff.reverse().toString());
	}
}
